package com.example.alipay_10_3.impl;

import com.example.alipay_10_3.Vo.Goods;
import com.example.alipay_10_3.Vo.Order;
import com.example.alipay_10_3.Vo.Price;
import com.example.alipay_10_3.mapper.PriceMapper;
import com.example.alipay_10_3.server.PriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class PriceServiceImpl implements PriceService {
    @Autowired
    //商品展示模块表
    private PriceMapper priceMapper;

    //商品展示模块
    //展示所有商品
    @Override
    public List<Price> select() {
        return priceMapper.selectAll();
    }

    //根据名称查找商品
    @Override
    public List<Price> findbyname(String name){
        return priceMapper.selectByName(name);
    }

    //加入购物车
    @Override
    public void save(Goods goods){
        priceMapper.saveAll(goods);
    }

    //购物车模块
    //购物车列表
    @Override
    public List<Goods> selectgoods(String userid){
        return priceMapper.allGoods(userid);
    }

    //删除某件商品
    @Override
    public void deleteGoods(String userid,Integer id){
        priceMapper.deleteOne(userid,id);
    }

    //清空购物车
    @Override
    public void deleteAllGoods(String userid){
        priceMapper.deleteAll(userid);
    }

    //订单管理模块
    //支付结束获取订单回调数据后存储数据库
    @Override
    public void orderstorage(Order order) { priceMapper.storage(order); }

    //根据用户id获取相应已购订单表
    @Override
    public List<Order> orderList(String userid){
        return priceMapper.order(userid);
    }

    //根据时间查找订单
    @Override
    public List<Order> findOrder(String uesrid,Timestamp start,Timestamp end){
        return priceMapper.ordersearch(uesrid,start,end);
    }
}
